package com.xuxin.baby.adapter;

import android.widget.ImageView;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.xuxin.baby.R;
import com.xuxin.baby.bean.ReaderVideoBean;
import com.xuxin.baby.glide.GlideApp;
import com.xuxin.baby.network.Retrofit;

import org.jetbrains.annotations.NotNull;

/**
 * Created by xu_xin
 * Created on 2020/12/22 0022
 */
public class MenuCourseAdapter extends BaseMultiItemQuickAdapter<ReaderVideoBean.ResultBean.ItemsBean, BaseViewHolder> {
    RequestOptions options = new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10));

    public MenuCourseAdapter() {
        addItemType(0, R.layout.item_menu_course);
        addItemType(1, R.layout.item_menu_reader);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, ReaderVideoBean.ResultBean.ItemsBean itemsBean) {
        switch (holder.getItemViewType()) {
            case 0:
                holder.setText(R.id.item_menu_course_name, itemsBean.getTitle());
                holder.setText(R.id.item_menu_course_content, itemsBean.getSummary());
                /**
                 * 加载图片
                 */
                ImageView item_menu_course_image = holder.findView(R.id.item_menu_course_image);
                String videoImage = Retrofit.image_url + itemsBean.getImageUrl();
                LogUtils.e("首页课程_image = " + videoImage);
                if (item_menu_course_image != null) {
                    GlideApp.with(getContext()).load(videoImage).placeholder(R.mipmap.img_placeholder160).apply(options).into(item_menu_course_image);
                }
                break;
            case 1:
                holder.setText(R.id.item_menu_reader_name, itemsBean.getTitle());
                holder.setText(R.id.item_menu_reader_content, itemsBean.getSummary());
                /**
                 * 加载图片
                 */
                ImageView item_menu_reader_image = holder.findView(R.id.item_menu_reader_image);
                String readerImage = Retrofit.image_url + itemsBean.getImageUrl();
                LogUtils.e("首页文章_image = " + readerImage);
                if (item_menu_reader_image != null) {
                    GlideApp.with(getContext()).load(readerImage).placeholder(R.mipmap.img_placeholder160).apply(options).into(item_menu_reader_image);
                }
                break;
        }
    }
}